#pragma once

#include "head.h"
#include "path.h"

// TODO: 完善mysql的stmt_的申请与释放
class Mysql
{
private:
    Mysql();
    ~Mysql();

    static Mysql *mysql_;
    static sql::Connection *conn_;
    static sql::Statement *stmt_;
    static sql::ResultSet *rs_;

    static void free();

    static void deleteFile_(int uid, int code, string fname);

public:
    static shared_ptr<User> queryUserByUid(int uid);
    static shared_ptr<User> queryUserByUnamePwd(string uname, string pwd);
    static shared_ptr<User> insert(string uname, string pwd);
    static void insertDir(int uid, int code, const string &path);
    static void insertFile(int uid, int code, const string &path, const string &md5);
    static void deleteUserByUid(int uid);
    static shared_ptr<VirtualDirec> queryFile(int uid, int code, string path);
    static bool deleteFile(int uid, int code, string fname);
    static void unlink(string md5sum);
    static void updateFile(int fid, int linked);
    static void insertFile(const string &fname, const string &md5);
    static shared_ptr<File> queryFile(const string &md5);
};